﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using QRCoder;
namespace 玩具商城管理系统.znew
{
    public partial class Nwuliu : Form
    {
        public Nwuliu()
        {
            InitializeComponent();
        }
        public static string Commodityid = "";
        public static string orderid = "";
        void showAll()
        {
            DB.GetCn();
           //string str = "select * from hot where hot_clientname='" + login.username + "'";
            string str = "select * from hot where hot_clientname='"+login.username+"'";
            SqlCommand cmd =new SqlCommand(str,DB.cn);
            SqlDataReader rdr = cmd.ExecuteReader();
            while (rdr.Read())
            {
                int index = dgvorder.Rows.Add();
                dgvorder.Rows[index].Cells[0].Value = rdr[4];
                dgvorder.Rows[index].Cells[1].Value = rdr[1];
                dgvorder.Rows[index].Cells[2].Value = rdr[2];
                string sdr="";
                if (rdr[14] != DBNull.Value)
                {
                    sdr = rdr[14].ToString(); 
                }
                else
                {
                    sdr = "商品还没有出货";
                }
                    if (rdr[15] != DBNull.Value)
                {
                    sdr= rdr[15].ToString();
                }
                if (rdr[16] != DBNull.Value)
                {
                    sdr = rdr[16].ToString();
                }
                QRCodeGenerator qrGenerator = new QRCodeGenerator();
                QRCodeData qrData = qrGenerator.CreateQrCode(sdr, QRCodeGenerator.ECCLevel.M);
                QRCode qrCode =new QRCode(qrData);
                Bitmap qrCodeImage = qrCode.GetGraphic(20);
                dgvorder.Rows[index].Cells["Column4"].Value = qrCodeImage;
            }
            rdr.Close();
        }

        private void Nwuliu_Load(object sender, EventArgs e)
        {
            timer1.Start();
            dgvorder.RowTemplate.Height = 90;
            showAll();
            label1.Parent = label2;
        }
        int index = 0;
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (index >= imageList1.Images.Count)
            index = 0;
                pictureBox1.Image = imageList1.Images[index];
                index++;
        }

        private void dgvorder_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int CIndex = e.ColumnIndex;
            if (CIndex == 4)
            {
                int rowindex = e.RowIndex;
                Commodityid = dgvorder.Rows[rowindex].Cells[1].Value.ToString();
                orderid = dgvorder.Rows[rowindex].Cells[0].Value.ToString();
               Nwuliuinformation tl = new Nwuliuinformation();
                tl.ShowDialog();
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            label1.Top = label2.Height / 2;
            if (label1.Left < -label1.Width)
            {
                label1.Left = label2.Width;
            }
            label1.Left -= 10;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
